$(function() {
			setTimeout('init("zh_CN")', 0);
		})
		window.updateEamilStrongContext = function() {
			var context = encodeURIComponent(tinymce.editors[0].getBody().innerHTML);
			var id = window.tinyModuleId();
			$.ajax({
				url: '/seeyon/kkES.do?method=saveEmailContext',
				type: "POST",
				data: {
					'id': id,
					'context': context
				},
				dataType: "json",
				success: function(result) {
					if(result.cdoe == '200') {
						console.log("保存成功：", result.cdoe);
					} else {
						console.log("保存失败：", result.cdoe);
					}
				},
				error: function(status) {
					console.log("erroe：", status);
				}
			});
		}
		function init(_language) {
			var flag = false;
			var _tr = $('section>div[class="cap4-textarea__left field-title"]');
			for(var i = 0; i < _tr.length; i++) {
				if(_tr[i].innerHTML == '邮件正文') {
					flag = true;
					var _html = '<td class="kk_case" colspan="5" rowspan="2" style="width: 900px;"><div class="mytextarea"></div></td>';
					$(_tr[i]).parents('td').html('').html(_html);
					break;
				}
			}
			if(flag) {
				tinyinit(_language)
			}
		}

		function tinyinit(_language) {
			$(".cap4-headers__btn.is-active").attr({
				"onclick":"window.updateEamilStrongContext()"
			})
			tinymce.init({
				selector: ".mytextarea", // change this value according to your HTML
				plugins: 'powerpaste searchreplace  directionality visualblocks visualchars codesample table charmap hr pagebreak nonbreaking anchor toc insertdatetime advlist lists wordcount textpattern help',
				language: _language, //zh_CN
				theme: "silver",
				relative_urls: false,
				//不允许拖动大小
				resize: false,
				visual: false,
				statusbar: false, // 状态栏 myButton
				font_formats: '微软雅黑=微软雅黑;楷体=楷体;宋体=宋体;仿宋=仿宋;黑体=黑体;幼圆=幼圆;Andale Mono=andale mono,times; Arial=arial,helvetica,sans-serif; Arial Black=arial black,avant garde; Book Antiqua=book antiqua,palatino; Comic Sans MS=comic sans ms,sans-serif; Courier New=courier new,courier; Georgia=georgia,palatino; Helvetica=helvetica; Impact=impact,chicago; Symbol=symbol; Tahoma=tahoma,arial,helvetica,sans-serif; Terminal=terminal,monaco; Times New Roman=times new roman,times; Trebuchet MS=trebuchet ms,geneva; Verdana=verdana,geneva; Webdings=webdings; Wingdings=wingdings,zapf dingbats',
				
				automatic_uploads: true, //自动上传	
				init_instance_callback: function(editor) {
					window.tinymce = tinymce;
					var id = window.tinyModuleId();
					$.ajax({
						url: '/seeyon/kkES.do?method=getEmailContext',
						type: "POST",
						data: {
							'id': id
						},
						dataType: "json",
						success: function(result) {
							if(typeof result.context !== 'undefined')
								editor.setContent(decodeURIComponent(result.context));
						}
					});
				},
				setup: function(editor) {
					
				},
				images_upload_handler: function(blobInfo, success, failure) {
					
				}
			});
		}